import java.util.HashMap;

/**
* @description: 535. TinyURL 的加密与解密
* @author hewei
* @date 2022/8/10 16:49
* @version 1.0
*/

public class Codec3 {
    private int count = 0;
    private HashMap<Integer, String> map = new HashMap<>();

    // Encodes a URL to a shortened URL.
    public String encode(String longUrl) {
        ++count;
        String res = "http://tinyurl.com/" + count;
        map.put(count, longUrl);
        return res;
    }

    // Decodes a shortened URL to its original URL.
    public String decode(String shortUrl) {
        return map.get(Integer.parseInt(shortUrl.substring(shortUrl.lastIndexOf("/") + 1)));
    }
}
